<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('模板导入选项')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-select-css"/>
</head>
<style>
    input::-webkit-outer-spin-button, input::-webkit-inner-spin-button {
        -webkit-appearance: none;
    }

    input[type="number"] {
        -moz-appearance: textfield;
    }

</style>
<body>
<div class="wrapper wrapper-content animated fadeInRight ibox-content" id="dv">
    <form class="form-horizontal m" id="form-importOption-add" AUTOCOMPLETE="OFF">
        <h4 class="form-header h4">导入选项</h4>
        <div class="form-group" id="xz">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">岗位名称：</label>
                    <div class="col-sm-8">
                        <input id="jobName" name="jobName" class="form-control" type="text"
                               placeholder="岗位名称"/>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group" id="deptId">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">所属部门：</label>
                    <div class="col-sm-8">
                        <select id="dept" name="dept" onchange="getJob()" class="form-control">
                            <option value="">请选择</option>
                            <option th:each="dep:${findAllDeptList}" th:value="${dep.deptId }"
                                    th:text="${dep.deptName }"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group" id="gx">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">岗位名称：</label>
                    <div class="col-sm-8">
                        <select name="jobId" id="jobId" class="form-control">

                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">导入类型：</label>
                    <div class="col-sm-8">
                        <input type="radio" checked="checked" name="option" value="0">新增模板&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="option" value="1">更新模板
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: select2-js"/>

<script th:inline="javascript">
    var prefix = ctx + 'acvTemplateManage';

    $(function () {

        //隐藏更新
        $("#gx").attr("style","display:none;");//隐藏div
    })

    $('input[type=radio][name=option]').change(function () {
        if(this.value == 0){
            $("#gx").attr("style","display:none;");
            $("#xz").attr("style","display:block;");
        }else if(this.value == 1){
            $("#gx").attr("style","display:block;");
            $("#xz").attr("style","display:none;");
        }
    })


    function submitHandler() {
        var option = $("input[name='option']:checked").val();
        if (option == '0') {
            var jobName = $("#jobName").val();
            var dept = $("#dept").val();

            if (jobName == '') {
                $.modal.alertWarning('请输入岗位名称!');
                return;
            }
            $.ajax({
                url: prefix + '/findJobCount',
                type: 'POST',
                data: {
                    "jobName" : jobName,
                    "dept" : dept
                },
                success: function (data) {
                    if(data.code == 1){
                        $.modal.alertWarning('岗位已存在!');
                        return;
                    }else{
                        var data = $("#form-importOption-add").serializeArray();
                        $.operate.save(prefix + "/insertTemplateList", data);
                        parent.location.reload();
                    }
                }
            })



        }else{
            var jobId = $("#jobId").val();
            if (jobId == '') {
                $.modal.alertWarning('请选择岗位名称!');
                return;
            }else{
                var data = $("#form-importOption-add").serializeArray();
                $.operate.save(prefix + "/insertTemplateList", data);
            }
        }
    }

    function getJob() {
        var tertiaryDeptId = $("#dept").val();
        var html = "";

        $.ajax({
            async: false,
            url: ctx + "acvEmpManage/getJobByTertiaryDeptId",
            data: {
                "tertiaryDeptId": tertiaryDeptId
            },
            type: "post",
            dataType: "json",
            success: function (data) {
                $("#jobId").empty();
                var arry = data;
                html += "<option value=''>请选择</option>";
                for (var i = 0; i < arry.length; i++) {
                    html += "<option value='"
                        + arry[i].jobId
                        + "'>"
                        + arry[i].jobName
                        + "</option>";
                }
                $("#jobId").append(html);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

</script>

</body>
</html>